home *** CD-ROM | disk | FTP | other *** search
/ Mac Format 1994 October / Macformat17.cdr / Shareware City / Developers / Kamprath's CDEF Pack ƒ / CDEF Sampler Program ƒ / samplerControls.c < prev    next >
C/C++ Source or Header  |  1994-06-12  |  6KB  |  279 lines

  1. #include "samplerControls.h"
  2. #include "number_picker.h"
  3.  
  4. ControlHandle        rocketCntl, timeButtonCntl, timeCntl, dateCntl, numberCntl;
  5. ControlHandle        squarePlain, squareBold, squareLarge;
  6. DateTimeRec            *theTime;
  7.  
  8. extern WindowPtr    samplerWindow;
  9.  
  10. void  SetUpWindowCntls( void )
  11. {
  12. Rect    ctrlRect;
  13.  
  14.     SetRect(&ctrlRect, 5,15,37,47);
  15.     rocketCntl = NewControl( samplerWindow, &ctrlRect, "\p", 
  16.                 TRUE, 0, 0, 1, 1000*16 + 0, 0 );
  17.                 
  18.     SetRect(&ctrlRect, 5,55,37,87);
  19.     timeButtonCntl = NewControl( samplerWindow, &ctrlRect, "\p", 
  20.                 TRUE, 0, 0, 1, 1000*16 + 1, 0 );
  21.     
  22.     theTime = (DateTimeRec *)NewPtrClear(sizeof(DateTimeRec));
  23.     GetTime( theTime );
  24.     
  25.     SetRect(&ctrlRect, 15,95,180,115);
  26.     timeCntl = NewControl( samplerWindow, &ctrlRect, "\pTime Control", TRUE,
  27.                             0, 0, 128, 16*1001 + kTimeVariation, 
  28.                             (long)(theTime));
  29.  
  30.     SetRect(&ctrlRect, 15,120,180,140);
  31.     dateCntl = NewControl( samplerWindow, &ctrlRect, "\pTime Control", TRUE,
  32.                             0, 0, 128, 16*1001 + kDateVariation, 
  33.                             (long)(theTime));
  34.  
  35.     SetRect(&ctrlRect, 5,145,155,165);
  36.     numberCntl = NewControl( samplerWindow, &ctrlRect, "\pNumber Control:", TRUE,
  37.                             0, 0, 5000, 16*1002 + 0, 0);
  38.                             
  39.     SetRect(&ctrlRect, 190,15,340,35);
  40.     squarePlain = NewControl( samplerWindow, &ctrlRect, "\pTimes Plain", TRUE,
  41.                             0, 12, times, 16*500, 0);
  42.  
  43.     SetRect(&ctrlRect, 190,40,340,65);
  44.     squareBold = NewControl( samplerWindow, &ctrlRect, "\pSystem Bold", TRUE,
  45.                             bold, 12, 0, 16*501, 0);
  46.     
  47.     SetRect(&ctrlRect, 190,70,340,100);
  48.     squareLarge = NewControl( samplerWindow, &ctrlRect, "\pCourier Large", TRUE,
  49.                             0, 18, courier, 16*502, 0);
  50.     
  51. }
  52.  
  53. pascal void NumCDEFProc(ControlHandle theControl, short theCode)
  54. {
  55. static long        lastTicks = 0;
  56.     
  57.     if (theCode == 0)
  58.         return ;
  59.     
  60.     if (TickCount() < lastTicks+10)
  61.         return;
  62.         
  63.     switch (theCode) 
  64.     {
  65.         case kNPArrowButtonUp: 
  66.             SetCtlValue( theControl, GetCtlValue(theControl)+1);
  67.             break;
  68.         case kNPArrowButtonDown: 
  69.             SetCtlValue( theControl, GetCtlValue(theControl)-1);
  70.             break;
  71.     }
  72.     
  73.     lastTicks = TickCount();
  74. }
  75.  
  76.  
  77.  
  78.  
  79. /*
  80.  * Time & Date CEF Handler routines
  81.  *
  82.  */
  83.  
  84.  
  85. long ticks, curWait;
  86.  
  87. void    HandleTimeCDEFClick(Point    where)
  88. {
  89. short            thePart, trackPart;
  90. ControlHandle    ch;
  91.  
  92.     ticks = TickCount();
  93.     curWait = 60;
  94.     trackPart = TrackControl( timeCntl, where, TimeCDEFAction);
  95.     
  96.     if (trackPart)
  97.     {
  98.         HandleTimeCDEFPart( timeCntl, trackPart);
  99.     }
  100. }
  101. void    HandleDateCDEFClick(Point    where)
  102. {
  103. short            thePart, trackPart;
  104. ControlHandle    ch;
  105.  
  106.     ticks = TickCount();
  107.     curWait = 60;
  108.     trackPart = TrackControl( dateCntl, where, DateCDEFAction);
  109.     
  110.     if (trackPart)
  111.     {
  112.         HandleDateCDEFPart( dateCntl, trackPart);
  113.     }
  114. }
  115.  
  116. pascal void TimeCDEFAction( ControlHandle ch, short part)
  117. {
  118.     if (TickCount() >= ticks + curWait)
  119.     {
  120.         HandleTimeCDEFPart( ch, part);
  121.         ticks = TickCount();
  122.         curWait = 15;
  123.     }
  124. }
  125. pascal void DateCDEFAction( ControlHandle ch, short part)
  126. {
  127.     if (TickCount() >= ticks + curWait)
  128.     {
  129.         HandleDateCDEFPart( ch, part);
  130.         ticks = TickCount();
  131.         curWait = 15;
  132.     }
  133. }
  134.  
  135. void HandleTimeCDEFPart( ControlHandle ch, short part)
  136. {
  137. DateTimeRec        *theTime;
  138. unsigned long    timeNum;
  139.  
  140.     switch (part)
  141.     {
  142.         case kHourItem:
  143.             SetCtlValue( ch, kHourItem);
  144.             break;
  145.         case kMinItem:
  146.             SetCtlValue( ch, kMinItem);
  147.             break;
  148.         case kAMPMItem:
  149.             SetCtlValue( ch, kAMPMItem);
  150.             break;
  151.         case kArrowButtonUp:
  152.             theTime = (DateTimeRec *)GetCRefCon(ch);
  153.             switch (GetCtlValue(ch))
  154.             {
  155.                 case kHourItem:
  156.                     if (theTime->hour < 23)
  157.                     {
  158.                         (theTime->hour)++;
  159.                     }
  160.                     break;
  161.                 case kMinItem:
  162.                     if (theTime->minute < 59)
  163.                     {
  164.                         (theTime->minute)++;
  165.                     }
  166.                     break;
  167.                 case kAMPMItem:
  168.                     if ( (theTime->hour + 12) <= 23)
  169.                     {
  170.                         (theTime->hour)  += 12;
  171.                     }
  172.                     break;
  173.             }
  174.             Draw1Control( ch );
  175.             break;
  176.         case kArrowButtonDown:
  177.             theTime = (DateTimeRec *)GetCRefCon(ch);
  178.             switch (GetCtlValue(ch))
  179.             {
  180.                 case kHourItem:
  181.                     if (theTime->hour > 0)
  182.                     {
  183.                         (theTime->hour)--;
  184.                     }
  185.                     break;
  186.                 case kMinItem:
  187.                     if (theTime->minute > 0)
  188.                     {
  189.                         (theTime->minute)--;
  190.                     }
  191.                     break;
  192.                 case kAMPMItem:
  193.                     if ( (theTime->hour - 12) >= 0)
  194.                     {
  195.                         (theTime->hour)  -= 12;
  196.                     }
  197.                     break;
  198.             }
  199.             Draw1Control( ch );
  200.             break;
  201.         default:
  202.             SetCtlValue( ch, 0);
  203.             break;
  204.     }
  205. }
  206. void HandleDateCDEFPart( ControlHandle ch, short part)
  207. {
  208. DateTimeRec        *theTime;
  209. unsigned long    timeNum;
  210.     switch (part)
  211.     {
  212.         case kMonthItem:
  213.             SetCtlValue( ch, kMonthItem);
  214.             break;
  215.         case kDateItem:
  216.             SetCtlValue( ch, kDateItem);
  217.             break;
  218.         case kYearItem:
  219.             SetCtlValue( ch, kYearItem);
  220.             break;
  221.         case kDayOfWeekItem:
  222.             SetCtlValue( ch, kDayOfWeekItem);
  223.             break;
  224.         case kArrowButtonUp:
  225.             theTime = (DateTimeRec *)GetCRefCon(ch);
  226.             switch (GetCtlValue(ch))
  227.             {
  228.                 case kMonthItem:
  229.                     if (theTime->month < 12)
  230.                     {
  231.                         (theTime->month)++;
  232.                     }
  233.                     break;
  234.                 case kDateItem:
  235.                 case kDayOfWeekItem:
  236.                     (theTime->day)++;
  237.                     Date2Secs(theTime, &timeNum);
  238.                     Secs2Date(timeNum, theTime);
  239.                     break;
  240.                 case kYearItem:
  241.                     if (theTime->year < 2040)
  242.                     {
  243.                         (theTime->year)++;
  244.                     }
  245.                     break;
  246.             }
  247.             Draw1Control( ch );
  248.             break;
  249.         case kArrowButtonDown:
  250.             theTime = (DateTimeRec *)GetCRefCon(ch);
  251.             switch (GetCtlValue(ch))
  252.             {
  253.                 case kMonthItem:
  254.                     if (theTime->month > 1)
  255.                     {
  256.                         (theTime->month)--;
  257.                     }
  258.                     break;
  259.                 case kDateItem:
  260.                 case kDayOfWeekItem:
  261.                     (theTime->day)--;
  262.                     Date2Secs(theTime, &timeNum);
  263.                     Secs2Date(timeNum, theTime);
  264.                     break;
  265.                 case kYearItem:
  266.                     if (theTime->year > 1904)
  267.                     {
  268.                         (theTime->year)--;
  269.                     }
  270.                     break;
  271.             }
  272.             Draw1Control( ch );
  273.             break;
  274.         default:
  275.             SetCtlValue( ch, 0);
  276.             break;
  277.     }
  278. }
  279.